class Place {
    constructor() {
        this.empty = true
    }
    in() {
        this.empty = false
    }
    out() {
        this.empty = true
    }
}

// 层
class Floor {
    constructor (places) {
        this.places = places || []
    }
    emptyPlaceNum() {
        let num = 0
        this.places.forEach(p => {
            p.empty ? num++ : ""
        })
        return num
    }
}
// park
class Park {
    constructor(floors) {
        this.floors = floors
        this.camera = this.camera
        this.screen = screen
        this.carList = new Map()
    }
    in(car) {
        // 1 拍照
        let info = this.camera.shot(car)
        // 2 进车位
        let place = this.floors[0].places[Number.parseInt(Math.random() * 100 % 100)]
        info.place = place
        place.in()
        this.carList.put(info.number, info)
    }
    out(car) {
        // 取出信息
        let info = this.carList[car.number]
        // 释放车位
        let place = info.place
        this.screen.show()
        // 删除
        this.carList.delete(car.number)
    }
    emptyInfo() {
        let info = this.floors.map(floor => {
            return `第${floor.index}层，空余车位: ${floor.emptyPlaceNum()}`
        }).join("\n")
        return info
    }
}
class Car {
    constructor(number) {
        this.number = number
    }
}
class Camera {
    constructor(){}
    shot(car) {
        return {
            number: car.number,
            inTime: Date.now()
        }
    }
}
class Screen {
    constructor(){}
    show(car, inTime) {
        console.log(`车牌号：${car.number}, 停车时间:${Date.now() - inTime}`)
    }
}

// 初始化
let floors = []
for (let i = 0; i < 3; i++) {
    let place = []
    for(let j = 0; j < 100; j ++) {
        place[j] = new Place()
    }
    floors[i] = place
}
let car1 = new Car(111)
let car2 = new Car(111)
let car3 = new Car(111)
let park = new Park(floors)
console.log("第一辆车进入")
console.log(park.emptyInfo())
park.in(car1)
console.log("第二辆车进入")
console.log(park.emptyInfo())
park.in(car2)
park.out(car1)
park.out(car2)


